<?php
/**
 * Created by PhpStorm.
 * User: macmini
 * Date: 2018/2/28
 * Time: 下午6:30
 */

namespace app\console\controller\goods;

use app\common\controller\Console;

class ItemCates extends Console {

    public function _empty() {
        return $this->fetch();
    }

    public function ua() {
        $model = model('UserAgents');
        $result = $model->order("ua_date desc")->paginate(15);

        $this->assign([
            'result' => $result
        ]);

        return $this->fetch();
    }

    public function ip() {
        $model = model('IpAddresses');
        $result = $model->order("ip_date desc")->paginate(15);

        $this->assign([
            'result' => $result
        ]);

        return $this->fetch();
    }

    public function share() {
        $model = model('Shares');
        $result = $model->field("shares.*,posts.post_id,posts.post_title,posts.post_thumb,posts.post_format")
            ->join("posts","posts.post_id=shares.post_id")
            ->order("shares.share_date desc")
            ->paginate(15)
            ->each(function ($item, $key){
                $item->post_thumb = json_decode($item->post_thumb, true);
            });

        $this->assign([
            'result' => $result
        ]);

        return $this->fetch();
    }

    public function post() {
        $model = model('Analytics');
        $result = $model->alias(["analytics"=>"a"])
            ->field("a.*,posts.post_id,posts.post_title,posts.post_thumb,posts.post_format,ip_addresses.ip_address,user_agents.ua_value")
            ->join("posts","posts.post_id=a.post_id")
            ->join("ip_addresses","ip_addresses.ip_id=a.ip_id")
            ->join("user_agents","user_agents.ua_id=a.ua_id")
            ->order("a.add_time desc")
            ->paginate(15)
            ->each(function ($item, $key){
                $item->post_thumb = json_decode($item->post_thumb, true);
            });

        $this->assign([
            'result' => $result
        ]);

        return $this->fetch();
    }

}
